﻿<%@ Page Title="Previous Studies :: Re-SeSS" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="PreviousStudies.aspx.cs" Inherits="ReSeSSApplication.PreviousStudies" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<script type="text/javascript">

    var hrefAttr = '';

    jQuery(document).ready(function () {

        jQuery('.icon-user').parent().popover({ placement: 'bottom' });

        jQuery('a.study-extract').click(function () {

            var waitSecond = Math.floor(3 + (Math.random() * (10 - 3)));
            hrefAttr = jQuery(this).attr('href');

            jQuery('#ExtractStudyModalDiv .progress .bar').css('width', '0px');
            jQuery('#ExtractStudyModalDiv').modal('show');
            jQuery('#ExtractStudyModalDiv .progress .bar').animate(
                {
                    width: '530px'
                },
                waitSecond * 1000,
                'linear',
                function () {
                    setTimeout("closeExtractWindow()", 2000);
                }
            );

            return false;
        });


        jQuery('a.study-delete').click(function () {
            var res = confirm("Do you really want to delete this study?\nAll data associated with this study will also be deleted from the system.");
            if (!res) {
                return false;
            }
        });


        jQuery('.study-share').click(function () {
            var studyId = jQuery(this).parent().parent().parent().children('td:last').find('input:hidden').val();
            jQuery('#bodyContent_ShareStudyIdHiddenField').val(studyId);

            jQuery("#bodyContent_txtMessage").val('');
            jQuery("#bodyContent_userListBox").find('option:selected').removeAttr("selected");
            jQuery("#bodyContent_userListBox").trigger("liszt:updated");

            jQuery('#bodyContent_userListBox').parent().parent().removeClass('error');
            jQuery('#bodyContent_userListBox').parent().find('.help-block').text('');
        });

        jQuery("#bodyContent_userListBox").chosen().change(function () {
            if (jQuery('#bodyContent_userListBox :selected').length <= 0) {
                jQuery('#bodyContent_userListBox').parent().parent().addClass('error');
                jQuery('#bodyContent_userListBox').parent().find('.help-block').text('No user selected to share the Study');
            } else {
                jQuery('#bodyContent_userListBox').parent().parent().removeClass('error');
                jQuery('#bodyContent_userListBox').parent().find('.help-block').text('');
            }
        });

        jQuery('#bodyContent_ShareStudyButton').click(function () {
            if (jQuery('#bodyContent_userListBox :selected').length <= 0) {
                jQuery('#bodyContent_userListBox').parent().parent().addClass('error');
                jQuery('#bodyContent_userListBox').parent().find('.help-block').text('No user selected to share the Study');
                return false;
            } else {
                jQuery('#bodyContent_userListBox').parent().parent().removeClass('error');
                jQuery('#bodyContent_userListBox').parent().find('.help-block').text('');
            }
        });

    });

    function closeExtractWindow() {
        jQuery('#ExtractStudyModalDiv').modal('hide');
        eval(hrefAttr);
    }

</script>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="bodyContent" runat="server">

    <div class="navbar"><div class="navbar-inner">
    <div class="container">
        
        <a class="brand" href="./Index.aspx">Re-SeSS</a>
        
        <ul class="nav">
            <li><a href="UserDashboard.aspx">Dashboard</a></li>
            <li><a href="NewStudy.aspx">New Study</a></li>
            <li class="active"><a href="PreviousStudies.aspx">Previous Studies</a></li>
        </ul>
        
        <ul class="nav pull-right">
            <li class="dropdown">
                <a data-toggle="dropdown" class="dropdown-toggle" href="#"><%=loggedInUserDTO.FirstName%>&nbsp;<%=loggedInUserDTO.LastName%> <b class="caret"></b></a>
                <ul class="dropdown-menu">
                    <li><a href="Profile.aspx">Profile</a></li>
                    <li><a href="ChangePassword.aspx">Change Password</a></li>
                    <li class="divider"></li>
                    <li><a href="LogOut.aspx">Logout</a></li></li>
                </ul>
            </li>
        </ul>
        
    </div>
    </div></div><!--navbar ends-->

    <ul class="breadcrumb">
    	<li class="active">You are in:&nbsp;&nbsp;&nbsp;</li>
    	<li><a href="UserDashboard.aspx">Dashboard</a> <span class="divider">/</span></li>
        <li class="active">Previous Studies</li>
    </ul><!--breadcrumb ends-->

    <div class="well" id="PrevStudyDiv">
    	
        <div class="alert alert-error" id="AlertError" runat="server"></div>
        <div class="alert alert-success" id="AlertSuccess" runat="server"></div>
    	<div class="alert alert-info" id="AlertInfo" runat="server"></div>

        
        <h2 style="margin-bottom:20px;">Previous Studies (Created and Shared)</h2>

        <asp:GridView ID="PreviousStudiesGridView" runat="server"
            GridLines="None" CellSpacing="-1"
            CssClass="table table-bordered table-striped"
            EmptyDataText="No Previous Study found." AutoGenerateColumns="false"
            onrowdatabound="PreviousStudiesGridView_RowDataBound"
            onrowcommand="PreviousStudiesGridView_RowCommand" 
            onrowcreated="PreviousStudiesGridView_RowCreated">
            <Columns>
                
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:HiddenField ID="SharedByHiddenField" Value='<%# Bind("SharedBy") %>' runat="server" />
                        <asp:HiddenField ID="SharedMessageHiddenField" Value='<%# Bind("SharedMessage") %>' runat="server" />
                        <asp:Label ID="lblShareUser" runat="server" Text="" Visible='<%# Convert.ToInt32(Eval("SharedBy").ToString()) > 0 %>'><i class="icon-user"></i></asp:Label>
                    </ItemTemplate>
                    <ItemStyle CssClass="center" />
                </asp:TemplateField>

                <asp:BoundField DataField="Name" HeaderText="Study Name" />
                <asp:BoundField DataField="CreationDate" HeaderText="Created" DataFormatString="{0:MMM dd, yyyy}" />
                <asp:BoundField DataField="ModifiedDate" HeaderText="Last Modified" DataFormatString="{0:MMM dd, yyyy}" />

                <asp:TemplateField HeaderText="No. of Reviewed Patients">
                    <ItemTemplate>
                        <asp:Label ID="lblReviewNumber" runat="server" Text=""></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Number of Flags">
                    <ItemTemplate>
                        <asp:Label ID="lblFlagNumber" runat="server" Text=""></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="StudyEditButton" runat="server" CausesValidation="false" 
                            CommandName="EditStudy" CommandArgument='<%# Bind("Id") %>' Text="<i class='icon-edit'></i>" ToolTip="Edit Study"></asp:LinkButton>
                    </ItemTemplate>
                    <ItemStyle CssClass="center" />
                </asp:TemplateField>

                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:Label ID="lblShareStudy" runat="server" Visible='<%# Convert.ToInt32(Eval("SharedBy").ToString()) <= 0 %>'>
                            <a href="#ShareStudyModalDiv" data-toggle="modal" title="Share Study" class="study-share"><i class='icon-share'></i></a>
                        </asp:Label>
                    </ItemTemplate>
                    <ItemStyle CssClass="center" />
                </asp:TemplateField>

                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="StudyExtractButton" runat="server" CausesValidation="False" 
                            CommandName="ExtractStudy" CommandArgument='<%# Bind("Id") %>' Text="<i class='icon-magnet'></i>" ToolTip="Extract Study" CssClass="study-extract"></asp:LinkButton>
                    </ItemTemplate>
                    <ItemStyle CssClass="center" />
                </asp:TemplateField>

                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="StudyReviewButton" runat="server" CausesValidation="False" 
                            CommandName="ReviewStudy" CommandArgument='<%# Bind("Id") %>' Text="<i class='icon-search'></i>" ToolTip="Review Study" CssClass="study-review"></asp:LinkButton>
                    </ItemTemplate>
                    <ItemStyle CssClass="center" />
                </asp:TemplateField>

                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:HiddenField ID="StudyIdHiddenField" Value='<%# Bind("Id") %>' runat="server" />
                        <asp:LinkButton ID="StudyDeleteButton" runat="server" CausesValidation="False" 
                            CommandName="DeleteStudy" CommandArgument='<%# Bind("Id") %>' Text="<i class='icon-trash'></i>" ToolTip="Delete Study" CssClass="study-delete"></asp:LinkButton>
                    </ItemTemplate>
                    <ItemStyle CssClass="center" />
                </asp:TemplateField>

            </Columns>
        </asp:GridView>

    </div><!--body ends-->

    <div class="modal hide fade" id="ExtractStudyModalDiv">
        <div class="modal-header">
            <h3>Extract data from EPR</h3>
        </div>
        <div class="modal-body">
            <p>Please wait while the process completes</p>
            <div class="progress progress-striped active">
                <div class="bar" style="width: 0px;"></div>
            </div>
        </div>
    </div><%--ExtractStudyModalDiv ends--%>

    <div class="modal hide fade" id="ShareStudyModalDiv">
        <div class="modal-header">
            <h3>Share Study</h3>
        </div>
        <div class="modal-body">

            <div class="form-horizontal"><fieldset>

                <asp:HiddenField ID="ShareStudyIdHiddenField" Value="0" runat="server" />

                <div class="control-group">
                    <asp:Label ID="lblUserList" runat="server" Text="Share To" AssociatedControlID="userListBox" CssClass="control-label"></asp:Label>
                    <div class="controls">
                        <asp:ListBox ID="userListBox" data-placeholder="Select user from the list" runat="server" Rows="6" SelectionMode="Multiple" CssClass="chzn-select input-xlarge"></asp:ListBox>
                        <p class="help-block"></p>
                    </div>
                </div>

                <div class="control-group">
                    <asp:Label ID="lblMessage" runat="server" Text="Message" AssociatedControlID="txtMessage" CssClass="control-label"></asp:Label>
                    <div class="controls">
                        <asp:TextBox ID="txtMessage" TextMode="MultiLine" Rows="4" Columns="20" CssClass="input-xlarge" runat="server"></asp:TextBox>
                        <p class="help-block"></p>
                    </div>
                </div>

            </fieldset></div>
        </div>
        <div class="modal-footer">
            <a href="#" class="btn" data-dismiss="modal">Close</a>
            <asp:Button ID="ShareStudyButton" runat="server" Text="Share Study" CssClass="btn btn-primary" 
                onclick="ShareStudyButton_Click" />
        </div>
    </div><%--ShareStudyModalDiv ends--%>

</asp:Content>
